package com.bhs.sansonglogistics.dialog;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.bean.OrderGoodsBean;
import com.bhs.sansonglogistics.utils.MyUtils;
import com.lxj.xpopup.core.BottomPopupView;

/**
 * 选择电话联系人
 */
public class BottomSelectPhoneDialog extends BottomPopupView implements View.OnClickListener {



    private TextView mTvOrderPlacer;
    private TextView mTvCallOrderPlacer;
    private TextView mTvConsigner;
    private TextView mTvConsignerAddress;
    private ImageView mIvCallConsigner;
    private TextView mTvConsignee;
    private TextView mTvConsigneeAddress;
    private ImageView mIvCallConsignee;
    private OrderGoodsBean data;

    public BottomSelectPhoneDialog(@NonNull Context context, OrderGoodsBean data) {
        super(context);
        this.data = data;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
        String cargo_mobile = data.getCargo_mobile();
        cargo_mobile = cargo_mobile.substring(cargo_mobile.length() - 4);
        String pickup_mobile=data.getPickup_mobile();
        pickup_mobile = pickup_mobile.substring(pickup_mobile.length() - 4);
        String receive_mobile=data.getReceive_mobile();
        receive_mobile = receive_mobile.substring(receive_mobile.length() - 4);
        mTvOrderPlacer.setText(String.format("下单人(尾号%s)", cargo_mobile));
        mTvConsigner.setText(String.format("发货人(尾号%s)", pickup_mobile));
        mTvConsignee.setText(String.format("收货人(尾号%s)", receive_mobile));
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_bottom_select_phone;
    }

    private void initView() {
       findViewById(R.id.iv_close).setOnClickListener(this);
        mTvOrderPlacer = findViewById(R.id.tv_order_placer);
        mTvCallOrderPlacer = findViewById(R.id.tv_call_order_placer);
        mTvConsigner = findViewById(R.id.tv_consigner);
        mTvConsignerAddress = findViewById(R.id.tv_consigner_address);
        mIvCallConsigner = findViewById(R.id.iv_call_consigner);
        mTvConsignee = findViewById(R.id.tv_consignee);
        mTvConsigneeAddress = findViewById(R.id.tv_consignee_address);
        mIvCallConsignee = findViewById(R.id.iv_call_consignee);
        mIvCallConsignee.setOnClickListener(this);
        mTvCallOrderPlacer.setOnClickListener(this);
        mIvCallConsigner.setOnClickListener(this);
        mTvConsigneeAddress.setText(String.format("地址：%s",data.getReceive_address()));
        mTvConsignerAddress.setText(String.format("地址：%s",data.getPickup_address()));
    }


    @Override
    public void onClick(View view) {
        dismiss();
        if(view.getId()==R.id.iv_call_consignee){
            MyUtils.callPhone(getActivity(),data.getReceive_mobile());
        }else if(view.getId()==R.id.tv_call_order_placer){
            MyUtils.callPhone(getActivity(),data.getCargo_mobile());
        }else if(view.getId()==R.id.iv_call_consigner){
            MyUtils.callPhone(getActivity(),data.getPickup_mobile());
        }
    }
}
